<?php
class CoreFactory
{
	private static $instance = array();
	private static $config = array();
	
	public static function setConfig($config){
		self::$config = array_merge(self::$config, (array)$config);
	}
	
	public static function view(){
		if(!isset(self::$instance['view'])){
			include_once PATH_CORE.'/ViewRenderer.php';
			self::$instance['view'] = new ViewRenderer();
		}
		return self::$instance['view'];
	}
	
	public static function session(){
		if(!isset(self::$instance['session'])){
			include_once PATH_CORE.'/Session.php';
			self::$instance['session'] = new Session();
		}
		return self::$instance['session'];
	}
	
	public static function db(){
		if(!isset(self::$instance['db'])){
			include_once PATH_CORE.'/db/Mysql.php';
			self::$instance['db'] = new Mysql();
		}
		return self::$instance['db'];
	}
	
	public static function log(){
		if(!isset(self::$instance['log'])){
			include_once PATH_CORE.'/log/Logger.php';
			$config=include(PATH_CFG.'/log.inc.php');
			self::$instance['log'] = new Logger($config);
		}
		return self::$instance['log'];
	}	
	
	/**
	 * 销毁数组
	 */
	public static function destroy(){
		self::$instance = array();
		self::$config = array();
	}
}
